package com.taotao.common.wxpay;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class MyWXConfig extends WXPayConfig{
 
	  private byte[] certData;
	  public static String appId="wxd9edb31e308100fe";
	  public static String mchId="1600589504";
	  public static String key="9cbd64d723f54b2c8ef860d729fb2ee3";
	  public static String certPath="/home/csos/deploy/apiclient_cert.p12";
	  
	  public MyWXConfig() throws Exception {
	        String certPath =MyWXConfig.certPath;
	        File file = new File(certPath);
	        InputStream certStream = new FileInputStream(file);
	        this.certData = new byte[(int) file.length()];
	        certStream.read(this.certData);
	        certStream.close();
	   }

	    public static void init(String certPath){
	    	MyWXConfig.certPath=certPath;
	    }

	  
	   public String getAppID() {
	       return "wxd9edb31e308100fe";
	   }  //小程序appid

	   public String getMchID() {
	       return "1600589504";
	   }  //商户号

	   /** 商户平台-账户中心-API安全中的密钥 */
	   public String getKey() {
	       return "9cbd64d723f54b2c8ef860d729fb2ee3";
	   }

	   public InputStream getCertStream() {
	       return new ByteArrayInputStream(this.certData);
	   }

	   public int getHttpConnectTimeoutMs() {
	       return 0;
	   }

	   public int getHttpReadTimeoutMs() {
	       return 0;
	   }
	   
	   @Override
	   public IWXPayDomain getWXPayDomain() { // 这个方法需要这样实现, 否则无法正常初始化WXPay
	        IWXPayDomain iwxPayDomain = new IWXPayDomain() {
	            public void report(String domain, long elapsedTimeMillis, Exception ex) {

	            }
	            public DomainInfo getDomain(WXPayConfig config) {
	                return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
	            }
	        };
	        return iwxPayDomain;
	    }
}